#include <iostream>
using namespace std;

extern "C" {
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
};

static lua_State *L = NULL;

int ladd (int x, int y)
{
    int sum;
    lua_getglobal (L, "add");
    lua_pushinteger (L, x);
    lua_pushinteger (L, y);
    lua_call (L, 2, 1);
    sum = (int)lua_tointeger (L, -1);
    lua_pop (L, 1);
    return sum;
}

int main (int argc, char **argv)
{
    L = luaL_newstate();
    luaL_openlibs (L);
    luaL_dofile (L, argv[1]);

    int sum = ladd (10, 20);
    cout << "sum=" << sum << endl;

    sum = ladd (10, 20);
    cout << "sum=" << sum << endl;

    sum = ladd (10, 20);
    cout << "sum=" << sum << endl;

    lua_close (L);
    return 0;
}
